//
//  FQDRegularArticleADFeedCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/12/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDRegularArticleADFeedCell.h"
#import "FQDRegularADFeedCellItem.h"
#import "FQDRestModel.h"

#import "Masonry.h"

@interface FQDRegularArticleADFeedCell ()

@property (nonatomic, strong) UILabel *adLabel;
@property (nonatomic, strong) UIImageView *adImageView;

@end

@implementation FQDRegularArticleADFeedCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareAdUI];
    }
    return self;
}

- (void)prepareAdUI
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.adLabel = [[UILabel alloc] init];
    self.adLabel.font = FQDRegularFontWithSize(12.0f);
    self.adLabel.textColor = [UIColor whiteColor];
    self.adLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4f];
    [self.contentView addSubview:self.adLabel];
    
    WeakSelf;
    [self.adLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(10);
        make.bottom.equalTo(weakSelf.contentView).offset(-10);
    }];
    
    UIImage *adTagImage = [UIImage imageNamed:@"adTag"];
    self.adImageView = [[UIImageView alloc] initWithImage:adTagImage];
    [self.contentView addSubview:self.adImageView];
    
    [self.adImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(15);
        make.bottom.equalTo(weakSelf.contentView).offset(-15);
        make.size.mas_equalTo(CGSizeMake(41, 15));
    }];
    
    self.adLabel.hidden = YES;
    self.adImageView.hidden = YES;
}

- (void)configureCellWithCellItem:(FQDRegularADFeedCellItem *)cellItem
{
    [super configureCellWithCellItem:cellItem];
    
    FQDAdFeed *adFeed = cellItem.adFeed;
    
    WeakSelf;
    if (adFeed.advertisement.title_reveal == 1) {
        // 显示全图
        [self.descImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf.contentView);
        }];
        self.adImageView.hidden = NO;
    } else {
        // 左边显示文字描述右边显示图片
        [self.descImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView);
            make.right.equalTo(weakSelf.contentView);
            make.width.equalTo(weakSelf.contentView).multipliedBy(0.5);
            make.height.equalTo(weakSelf.contentView);
        }];
        self.adImageView.hidden = YES;
    }
}

+ (NSString *)reuseId
{
    return @"FQDRegularArticleADFeedCell";
}

@end
